using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.Scene;
using MicroMsg.UI.Page;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Microsoft.Phone.Tasks;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.Util
{
	public class ToolFunction
	{
		public const int cNRemarkMaxLen = 20;
		public const int cNFavoriteGroupIndex = 0;
		public const int cNAtGroupIndex = 1;
		public const int cNQunIndex = 2;
		public const int cNStrokeIndexStated = 3;
		public const int cNContactGroupIndexStated = 22;
		public const char cCFavoriteGroupKey = '*';
		public const char cCQunGroupKey = '&';
		public const int cNStrokCntMax = 19;
		public const string strACodeTitle = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ#";
		public const int MIN_ACCOUNT_LENGTH = 6;
		public const int MAX_ACCOUNT_LENGTH = 20;
		public const int MIN_PASSWORD_LENGTH = 6;
		public const int MAX_PASSWORD_LENGTH = 16;
		private static string[] phoneNumberPrefix = new string[]
		{
			"1"
		};
		public static List<string> systemPluginName;
		public static List<string> systemPluginNameNeedShow;
		public static List<string> systemPluginNameCantDel;
		public static string groupTitle;
		public static string groupContactHeaders;
		private static ProgressIndicator sProgressIndicator;
		private static Size sizeMax;
		private static IApplicationBar sAppBarToHide;
		private static bool sBIsVisiAppBarOrigin;
		private static string InitGroupTitle()
		{
			string text = "*@&";
			for (int i = 1; i <= 19; i++)
			{
				text += (char)i;
			}
			return text + "ABCDEFGHIJKLMNOPQRSTUVWXYZ#";
		}
		public static bool checkIsPhoneNumber(string strNums)
		{
			return !string.IsNullOrWhiteSpace(strNums) && strNums.get_Length() >= 3;
		}
		public static bool checkIsChinaNumber(string strNums)
		{
			if (string.IsNullOrWhiteSpace(strNums))
			{
				return false;
			}
			if (!ToolFunction.checkIsNumber(strNums))
			{
				return false;
			}
			for (int i = 0; i < ToolFunction.phoneNumberPrefix.Length; i++)
			{
				if (strNums.StartsWith(ToolFunction.phoneNumberPrefix[i], 0))
				{
					return true;
				}
			}
			return false;
		}
		public static bool checkIsHongkongNumber(string strNums)
		{
			return !string.IsNullOrWhiteSpace(strNums);
		}
		public static bool checkIsTaiwanNumber(string strNums)
		{
			return !string.IsNullOrWhiteSpace(strNums);
		}
		public static bool checkIsJapenNumber(string strNums)
		{
			return !string.IsNullOrWhiteSpace(strNums);
		}
		public static bool checkIsUSNumber(string strNums)
		{
			return !string.IsNullOrWhiteSpace(strNums);
		}
		public static bool checkIsMailAddress(string strNums)
		{
			if (strNums != null && strNums.get_Length() != 0)
			{
				int num = strNums.IndexOf('@');
				int num2 = strNums.IndexOf('.');
				if (-1 != num)
				{
					if (-1 != num2)
					{
						return num2 - num >= 1 && num2 != strNums.get_Length() - 1;
					}
				}
				return false;
			}
			return false;
		}
		public static bool checkIsNumber(string strNums)
		{
			if (strNums != null && strNums.get_Length() != 0)
			{
				for (int i = 0; i < strNums.get_Length(); i++)
				{
					if (strNums.get_Chars(i) < '0' || strNums.get_Chars(i) > '9')
					{
						return false;
					}
				}
				return true;
			}
			return false;
		}
		public static bool checkIsLegalQQNum(string strNums)
		{
			return !ToolFunction.isEmptyString(strNums) && ToolFunction.checkIsNumber(strNums) && strNums.get_Length() >= 3;
		}
		public static bool checkIsLegalMMName(string strNums)
		{
			return strNums != null && strNums.get_Length() != 0;
		}
		public static bool checkIsLegalNickName(string strNums)
		{
			if (ToolFunction.isBlankString(strNums))
			{
				return false;
			}
			if (strNums.get_Length() < 6 || strNums.get_Length() >= 20)
			{
				return false;
			}
			if (!ToolFunction.checkCharIsAlpha(strNums.get_Chars(0)))
			{
				return false;
			}
			for (int i = 0; i < strNums.get_Length(); i++)
			{
				if (!ToolFunction.checkCharIsAlpha(strNums.get_Chars(i)) && !ToolFunction.checkCharIsNumber(strNums.get_Chars(i)) && strNums.get_Chars(i) != '-' && strNums.get_Chars(i) != '_')
				{
					return false;
				}
			}
			return true;
		}
		public static bool checkIsLegalRemark(string strRemark)
		{
			return !string.IsNullOrWhiteSpace(strRemark);
		}
		public static bool checkCharIsAlpha(char tempChar)
		{
			return (tempChar >= 'a' && tempChar <= 'z') || (tempChar >= 'A' && tempChar <= 'Z');
		}
		public static char getUperChar(char tempChar)
		{
			if (tempChar >= 'a' && tempChar <= 'z')
			{
				tempChar -= ' ';
			}
			return tempChar;
		}
		public static bool checkCharIsNumber(char tempChar)
		{
			return tempChar >= '0' && tempChar <= '9';
		}
		public static bool checkIsLegalPassWord(string strNums)
		{
			return !string.IsNullOrWhiteSpace(strNums) && strNums.get_Length() >= 6 && strNums.get_Length() < 16;
		}
		public static ObservableCollection<T> ListToObserva<T>(List<T> inputList)
		{
			if (inputList == null)
			{
				return null;
			}
			return new ObservableCollection<T>(inputList);
		}
		public static bool checkIsStrSystemPlugin(string uerName)
		{
			if (uerName == null)
			{
				return false;
			}
			bool result;
			using (List<string>.Enumerator enumerator = ToolFunction.systemPluginName.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					string current = enumerator.get_Current();
					if (current.CompareTo(uerName) == 0)
					{
						result = true;
						return result;
					}
				}
				return false;
			}
			return result;
		}
		public static bool checkIsSysPlugNeedShow(string uerName)
		{
			if (uerName == null)
			{
				return false;
			}
			bool result;
			using (List<string>.Enumerator enumerator = ToolFunction.systemPluginNameNeedShow.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					string current = enumerator.get_Current();
					if (current.CompareTo(uerName) == 0)
					{
						result = true;
						return result;
					}
				}
				return false;
			}
			return result;
		}
		public static int getIndexOfGroupList(char cHeader)
		{
			int num = ToolFunction.groupTitle.IndexOf(cHeader);
			if (-1 == num)
			{
				return ToolFunction.groupTitle.IndexOf('#');
			}
			return num;
		}
		public static bool GotoPageForUserControl(string string_0, object[] object_0, bool isRemoveMe = false)
		{
			PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
			BasePage basePage = phoneApplicationFrame.get_Content() as BasePage;
			if (basePage == null)
			{
				return false;
			}
			basePage.GoToPage(string_0, object_0, isRemoveMe);
			return true;
		}
		public static string GetNumbersFromString(string strToConvert)
		{
			string text = "";
			for (int i = 0; i < strToConvert.get_Length(); i++)
			{
				char c = strToConvert.get_Chars(i);
				if (c >= '0' && c <= '9')
				{
					text += c;
				}
			}
			return text;
		}
		public static string GetInterNationalNumbers(string strToConvert)
		{
			string text = "";
			int num = 0;
			for (int i = 0; i < strToConvert.get_Length(); i++)
			{
				char c = strToConvert.get_Chars(i);
				if (num == 0 && c == '+')
				{
					text += c;
				}
				if (c >= '0' && c <= '9')
				{
					text += c;
				}
			}
			return text;
		}
		public static bool SetAppBarVisibility(bool bIsVisible)
		{
			PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
			BasePage basePage = phoneApplicationFrame.get_Content() as BasePage;
			if (basePage == null)
			{
				return false;
			}
			if (basePage.get_ApplicationBar() == null)
			{
				return false;
			}
			basePage.get_ApplicationBar().set_IsVisible(bIsVisible);
			return true;
		}
		public static bool isEmptyString(string strTemp)
		{
			return strTemp == null || 0 == strTemp.get_Length();
		}
		public static bool isBlankString(string strTemp)
		{
			string strTemp2 = "";
			if (strTemp != null)
			{
				strTemp2 = strTemp.Trim();
			}
			return ToolFunction.isEmptyString(strTemp2);
		}
		public static int getStrDisLen(string strTemp)
		{
			if (ToolFunction.isEmptyString(strTemp))
			{
				return 0;
			}
			int num = 0;
			for (int i = 0; i < strTemp.get_Length(); i++)
			{
				char c = strTemp.get_Chars(i);
				if (c > 'ÿ')
				{
					num += 2;
				}
				else
				{
					num++;
				}
			}
			return num;
		}
		public static string SubStringDisLen(string strTemp, int disLen)
		{
			if (ToolFunction.isEmptyString(strTemp))
			{
				return "";
			}
			while (ToolFunction.getStrDisLen(strTemp) > disLen)
			{
				strTemp = strTemp.Substring(0, strTemp.get_Length() - 1);
			}
			return strTemp;
		}
		public static BasePage GetRootPage()
		{
			PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
			if (phoneApplicationFrame == null)
			{
				return null;
			}
			BasePage basePage = phoneApplicationFrame.get_Content() as BasePage;
			if (basePage == null)
			{
				return null;
			}
			return basePage;
		}
		public static string GetRegionShow(string strProvince, string strCity)
		{
			strProvince = ToolFunction.trimToEmpty(strProvince);
			strCity = ToolFunction.trimToEmpty(strCity);
			if (strProvince.get_Length() == 0)
			{
				return strCity;
			}
			if (strCity.get_Length() == 0)
			{
				return strProvince;
			}
			string result;
			if (!("Others" == strProvince) && !("其他" == strProvince))
			{
				if (R.isEnglish())
				{
					result = ToolFunction.trimToEmpty(strCity) + " " + ToolFunction.trimToEmpty(strProvince);
				}
				else
				{
					result = ToolFunction.trimToEmpty(strProvince) + " " + ToolFunction.trimToEmpty(strCity);
				}
			}
			else
			{
				result = strCity;
			}
			return result;
		}
		public static string trimToEmpty(string string_0)
		{
			if (string_0 != null)
			{
				return string_0.Trim();
			}
			return "";
		}
		public static bool isLanguageEnglish()
		{
			string strUserSetLanguage = GConfigMgr.settings.strUserSetLanguage;
			return !strUserSetLanguage.Contains("zh");
		}
		public static DoubleAnimation createAnimation(double? from, double double_0, DependencyObject target, string property, uint duration)
		{
			DoubleAnimation doubleAnimation = new DoubleAnimation();
			doubleAnimation.set_From(from);
			doubleAnimation.set_To(new double?(double_0));
			doubleAnimation.set_Duration(TimeSpan.FromMilliseconds(duration));
			Storyboard.SetTarget(doubleAnimation, target);
			Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath(property, new object[0]));
			return doubleAnimation;
		}
		public static DoubleAnimationUsingKeyFrames createDoubleKeyAni(double[] aKeyValue, int[] aKeyTime, DependencyObject target, string property, uint duration)
		{
			if (aKeyTime != null && aKeyTime != null && target != null && !string.IsNullOrEmpty(property))
			{
				if (aKeyTime.Length == aKeyTime.Length)
				{
					DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames();
					for (int i = 0; i < aKeyValue.Length; i++)
					{
						LinearDoubleKeyFrame linearDoubleKeyFrame = new LinearDoubleKeyFrame();
						linearDoubleKeyFrame.set_KeyTime(TimeSpan.FromMilliseconds((double)aKeyTime[i]));
						linearDoubleKeyFrame.set_Value(aKeyValue[i]);
						doubleAnimationUsingKeyFrames.get_KeyFrames().Add(linearDoubleKeyFrame);
					}
					Storyboard.SetTarget(doubleAnimationUsingKeyFrames, target);
					Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrames, new PropertyPath(property, new object[0]));
					return doubleAnimationUsingKeyFrames;
				}
			}
			DebugEx.debugBreak();
			return new DoubleAnimationUsingKeyFrames();
		}
		public static string GetSnsTimelineTime(long nCreatTime)
		{
			DateTime dateTime = Util.SencondsToLocalTime(nCreatTime);
			DateTime currentTime = DateTime.get_Now().ToLocalTime();
			int num = (int)currentTime.Subtract(dateTime).get_TotalMinutes();
			if (num < -10)
			{
				return null;
			}
			if (Util.isYesterday(currentTime, dateTime))
			{
				return strings.SessionYesterday;
			}
			if (num < 60)
			{
				if (num <= 0)
				{
					num = 1;
				}
				return string.Format(strings.Util_BeforeMinFormat, num);
			}
			if (num < 1440)
			{
				return string.Format(strings.Util_BeforeHourFormat, num / 60);
			}
			return string.Format(strings.Util_BeforeDayFormat, num / 60 / 24);
		}
		public static void GotoWebLink(string strUrl)
		{
			if (string.IsNullOrEmpty(strUrl))
			{
				return;
			}
			if (BasePage.CanDoBackSysTask())
			{
				BasePage.DoBackSysTask();
				try
				{
					WebBrowserTask webBrowserTask = new WebBrowserTask();
					webBrowserTask.set_Uri(new Uri(strUrl));
					webBrowserTask.Show();
				}
				catch
				{
					BasePage.EnableBackSysTask();
					Log.smethod_5("Toolfunction", "GotoWebLink failed");
				}
				return;
			}
		}
		public static void GotoWebLinkInWebView(string strUrl, GetA8KeyScene scene = GetA8KeyScene.MMGETA8KEY_SCENE_UNKNOW)
		{
			if (string.IsNullOrEmpty(strUrl))
			{
				return;
			}
			WebViewPage.GotoThisPage(strUrl, scene);
		}
		public static void GotoWebLinkInWebView(WebViewPageConfig config, GetA8KeyScene scene = GetA8KeyScene.MMGETA8KEY_SCENE_UNKNOW)
		{
			if (config == null)
			{
				return;
			}
			WebViewPage.GotoThisPage(config, scene);
		}
		public static Rect GetElementPos(FrameworkElement element)
		{
			GeneralTransform generalTransform = element.TransformToVisual(Application.get_Current().get_RootVisual());
			Point point = generalTransform.Transform(new Point(0.0, 0.0));
			Rect result = new Rect(point.get_X(), point.get_Y(), element.get_ActualWidth(), element.get_ActualHeight());
			return result;
		}
		public static void RemoveCtrlParent(FrameworkElement element)
		{
			if (element.get_Parent() != null)
			{
				Panel panel = element.get_Parent() as Panel;
				if (panel != null)
				{
					panel.get_Children().Remove(element);
				}
			}
		}
		public static Rect GetImageFillModeRect(Size Bound, Size OriginSize)
		{
			Rect result = new Rect(0.0, 0.0, 480.0, 800.0);
			if (OriginSize.get_Height() > 0.0 && OriginSize.get_Width() > 0.0 && Bound.get_Width() > 0.0 && Bound.get_Height() > 0.0)
			{
				double num = Bound.get_Height() / Bound.get_Width();
				double num2 = OriginSize.get_Height() / OriginSize.get_Width();
				if (num2 >= num)
				{
					result.set_Height(Bound.get_Height());
					result.set_Width(Bound.get_Height() / num2);
				}
				else
				{
					result.set_Height(Bound.get_Width() * num2);
					result.set_Width(Bound.get_Width());
				}
				result.set_X(Bound.get_Width() / 2.0 - result.get_Width() / 2.0);
				result.set_Y(Bound.get_Height() / 2.0 - result.get_Height() / 2.0);
				return result;
			}
			return result;
		}
		public static BitmapImage GetImgFromContentSource(string strPath)
		{
			if (string.IsNullOrEmpty(strPath))
			{
				return null;
			}
			BitmapImage bitmapImage = new BitmapImage();
			bitmapImage.set_UriSource(new Uri(strPath, 0));
			return bitmapImage;
		}
		public static void ShowSystemTrayProgressIndicator(string strWording = "")
		{
			if (ToolFunction.sProgressIndicator == null)
			{
				ToolFunction.sProgressIndicator = new ProgressIndicator();
			}
			ToolFunction.sProgressIndicator.set_Text(strWording);
			SystemTray.set_ProgressIndicator(ToolFunction.sProgressIndicator);
			SystemTray.get_ProgressIndicator().set_IsVisible(true);
			SystemTray.get_ProgressIndicator().set_IsIndeterminate(true);
		}
		public static void SetSystemTrayProgressIndicatorWording(string strWording)
		{
			if (ToolFunction.sProgressIndicator != null)
			{
				ToolFunction.sProgressIndicator.set_Text(strWording);
			}
		}
		public static void HideSystemTrayProgressIndicator()
		{
			SystemTray.set_ProgressIndicator(null);
			if (ToolFunction.sProgressIndicator != null)
			{
				ToolFunction.sProgressIndicator.set_IsVisible(false);
				ToolFunction.sProgressIndicator.set_Text("");
				ToolFunction.sProgressIndicator.set_IsIndeterminate(false);
			}
		}
		public static Size GetDesireSize(UIElement uielement_0)
		{
			if (uielement_0 == null)
			{
				return default(Size);
			}
			uielement_0.Measure(ToolFunction.sizeMax);
			return uielement_0.get_DesiredSize();
		}
		public static void HideRootPageAppbar()
		{
			PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
			BasePage basePage = phoneApplicationFrame.get_Content() as BasePage;
			if (basePage == null)
			{
				return;
			}
			if (basePage.get_ApplicationBar() == null)
			{
				return;
			}
			ToolFunction.sAppBarToHide = basePage.get_ApplicationBar();
			ToolFunction.sBIsVisiAppBarOrigin = ToolFunction.sAppBarToHide.get_IsVisible();
			ToolFunction.sAppBarToHide.set_IsVisible(false);
		}
		public static void ResumeRootPageAppbar()
		{
			if (ToolFunction.sAppBarToHide != null)
			{
				ToolFunction.sAppBarToHide.set_IsVisible(ToolFunction.sBIsVisiAppBarOrigin);
				ToolFunction.sAppBarToHide = null;
			}
		}
		static ToolFunction()
		{
			// Note: this type is marked as 'beforefieldinit'.
			List<string> list = new List<string>();
			list.Add("weibo");
			list.Add("fmessage");
			list.Add("floatbottle");
			list.Add("medianote");
			list.Add("qmessage");
			list.Add("qqmail");
			list.Add("tmessage");
			list.Add("masssend");
			list.Add("newsapp");
			list.Add("blogapp");
			ToolFunction.systemPluginName = list;
			List<string> list2 = new List<string>();
			list2.Add("fmessage");
			list2.Add("qmessage");
			list2.Add("masssend");
			ToolFunction.systemPluginNameNeedShow = list2;
			List<string> list3 = new List<string>();
			list3.Add("fmessage");
			ToolFunction.systemPluginNameCantDel = list3;
			ToolFunction.groupTitle = ToolFunction.InitGroupTitle();
			ToolFunction.groupContactHeaders = "ABCDEFGHIJKLMNOPQRSTUVWXYZ#";
			ToolFunction.sProgressIndicator = null;
			ToolFunction.sizeMax = new Size(1.7976931348623157E+308, 1.7976931348623157E+308);
			ToolFunction.sAppBarToHide = null;
			ToolFunction.sBIsVisiAppBarOrigin = true;
		}
	}
}
